/*
 * @Author: duanguang
 * @Date: 2021-11-24 22:04:07
 * @LastEditTime: 2022-02-23 17:36:47
 * @LastEditors: duanguang
 * @Description:  git 仓库数据表
 * @FilePath: /legions-server/app/model/repository_project.ts
 * 「扫去窗上的尘埃，才可以看到窗外的美景。」
 */
import { Model, Document, Schema } from '.';
import { Application } from 'egg';

/** 项目仓库实体 */
export class RepositoryProject {
    /** 项目名称 */
    project_name: string = '';

    /** 描述 */
    project_description: string = '';

    /** 仓库源 */
    repository_source: string = '';

    /** 项目分组 */
    project_group: string = ''
    
    /** 仓库地址 */
    repository_https: string = ''
    
    /** 仓库ssh */
    repository_ssh:string=''
    
    /** 消息通知类型 */
    message_notify: string = ''
    
    /** 消息通知渠道 */
    message_channel:string=''
    
    /** gitlab 仓库项目id */
    gitlab_project_id: string = ''
    
    /** 创建人id */
    creator_id: string = ''
    
    /** 创建人 */
    creator: string = ''
    
    /** 创建时间 */
    create_time: number = new Date().getTime();

    
    /** 修改时间 */
    update_time: number = new Date().getTime();
}

export interface IRepositoryProjectModel extends Document, RepositoryProject {}

export default function RepositoryProjectModel(
    app: Application,
): Model<IRepositoryProjectModel> {
    const mongoose = app.mongoose;
    const Schema = mongoose.Schema;
    const repositoryProjectSchema: Schema = new Schema({
        project_name: { type: String, unique: true },
        project_description: { type: String },
        repository_source: { type: String },
        project_group: { type: String },
        repository_https: { type: String },
        repository_ssh: { type: String },
        message_notify: { type: String },
        message_channel: { type: String },
        gitlab_project_id: { type: String },
        creator_id: { type: String },
        creator: { type: String },
        create_time: { type: Number },
        update_time: { type: Number },
    }, {
        timestamps: { updatedAt: 'update_time', createdAt: 'create_time' },
    });
    return mongoose.model<IRepositoryProjectModel>(
        'repository_project',
        repositoryProjectSchema,
    );
}
